package nowcoder.hw.hj08;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/***
 * hashmap 性能远高于treemap，特别在put频繁的操作中
 * treemap是维护的链表，每次操作都要经过comparator,巨耗时
 */
public class Main1 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String ns = reader.readLine();
        Map<Integer, Integer> res = new HashMap<>();
        int n = Integer.valueOf(ns);
        while (n-- > 0) {
            String[] mapping = reader.readLine().split(" ");
            Integer key = Integer.valueOf(mapping[0]);
            Integer val = Integer.valueOf(mapping[1]);
            res.put(key, res.getOrDefault(key, 0) + val);
        }
        StringBuilder stringBuilder = new StringBuilder();
        Integer[] a = new Integer[res.size()];
        Arrays.sort(res.keySet().toArray(a));
        for (int i = 0; i < a.length; i++) {
            stringBuilder.append(a[i]).append(" ").append(res.get(a[i])).append("\n");
        }
        stringBuilder.deleteCharAt(stringBuilder.length() - 1);
        System.out.println(stringBuilder);
    }
}
